package de.windeln.marketing.campaign.model;

import java.io.IOException;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.BasicSerializerFactory;
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;

public class JacksonObjectMapper extends ObjectMapper{
	
	private static final long serialVersionUID = 6655280692564937545L;

	public JacksonObjectMapper(){
//		disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
//		disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES); 
//		enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
//		configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
//		configure(SerializationFeature.WRAP_ROOT_VALUE, true);
//		 setSerializationInclusion(Include.NON_EMPTY);
//		setde
//		configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
		
//		BeanSerializerFactory factory = new Defaultser
//        addSpecificMapping(String.class, new NullToEmptySerializer());
//        this.setSerializerFactory(sf);
		
//		 setSerializationInclusion(JsonInclude.Include.ALWAYS);
		
	 SimpleModule module = new SimpleModule("NullAndEmptyStringModule");
	    // functionality includes ability to register serializers, deserializers, add mix-in annotations etc:
//	    module.addSerializer(String.class, new NullToEmptySerializer()); // new NullToEmptySerializer()
	    module.addDeserializer(String.class, new EmptyStringToNullDeserializer());
	    // and the magic happens here when we register module with mapper:
	    registerModule(module);
	
	    
//		_rootDeserializers.put(new JavaType(){, new JsonDeserializer<Object>() {
//
//			@Override
//			public Object deserialize(JsonParser jp, DeserializationContext ctxt)
//					throws IOException, JsonProcessingException {
//				return null;
//			}
//		});
//		  // First: need a custom serializer provider
//	    SerializerProvider nullProvider = new StdSerializerProvider();
//	 module.
//		getSerializerProvider().setNullValueSerializer(NullSerializer.instance);
	    // And then configure mapper to use it
//	    ObjectMapper m = new ObjectMapper();
//	    m.setSerializerProvider(sp);
	    
	}

}
